/**
 * 
 */
package engine;

import interfaces.IFocalElement;
import massDistribution.JointMassDistribution;

/**
 * @author Elisa Costante
 * 
 */
public class BestResultPolicyManager {

	public static IFocalElement getBestElement(BestResultPolicy policy,
			JointMassDistribution mass) {
		IFocalElement bestElement = null;

		switch (policy.getValue()) {
		case 1:
			// BEST BPA
			double bestBpa = 0;
			for (IFocalElement focalElement : mass.getBodyOfEvidence()) {
				if (focalElement.getBpa() > bestBpa) {
					bestBpa = focalElement.getBpa();
					bestElement = focalElement;
				}
			}

			break;

		case 2:

			// BEST BELIEF

			double bestBelief = 0;
			for (IFocalElement focalElement : mass.getBodyOfEvidence()) {
				if (focalElement.getBpa() > bestBelief) {
					bestBelief = focalElement.getBelief();
					bestElement = focalElement;
				}
			}
			break;

		case 3:

			// LESS UNCERTAINITY
			double lessUncertainity = 0;
			for (IFocalElement focalElement : mass.getBodyOfEvidence()) {
				if (focalElement.getUncertainty() < lessUncertainity) {
					lessUncertainity = focalElement.getUncertainty();
					bestElement = focalElement;
				}
			}
			break;

		default:
			break;
		}
		return bestElement;
	}
}
